import 'package:flutter/material.dart';
import 'package:netstorage/pages/expansion_tile_page.dart';
import 'package:netstorage/pages/flutter2JS_by_url.dart';
import 'package:netstorage/pages/flutter2js_by_runjs.dart';
import 'package:netstorage/pages/flutter_h5_auth_channel.dart';
import 'package:netstorage/pages/flutter_h5_auth_cookie.dart';
import 'package:netstorage/pages/flutter_h5_jump_asset.dart';
import 'package:netstorage/pages/flutter_h5_jump_html_file.dart';
import 'package:netstorage/pages/gridview_page.dart';
import 'package:netstorage/pages/home.dart';
import 'package:netstorage/pages/horizontal_list_page.dart';
import 'package:netstorage/pages/js2flutter_by_channel.dart';
import 'package:netstorage/pages/js2flutter_by_url.dart';
import 'package:netstorage/pages/loadmore_page.dart';
import 'package:netstorage/pages/my_page.dart';
import 'package:netstorage/pages/search_page.dart';
import 'package:netstorage/pages/travel_page.dart';
import 'package:netstorage/pages/vertical_list_page.dart';

/**
 * 首页底部导航器
 */
class TabNavigator extends StatefulWidget {
  const TabNavigator({super.key});

  @override
  State<TabNavigator> createState() => _TabNavigatorState();
}

class _TabNavigatorState extends State<TabNavigator> {
  int _currentPageIndex = 0;
  final _defaultColor = Colors.grey;
  final _activeColor = Colors.blue;
  final PageController _controller = PageController(
    initialPage: 0, // 默认打开第一个页面
  );
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        //physics: const NeverScrollableScrollPhysics(),// 防止左右滚动
        children: [Home(),SearchPage(hideLeft: true,keyword: '苏州',),TravelPage(),MyPage()],
        // children: [Home(),ExpansionTilePage(),HorizontalListPage(),VerticalListPage()],
        // children: [Home(),ExpansionTilePage(),LoadmorePage(),GridviewPage()],
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentPageIndex,
        onTap: (index){
          _controller.jumpToPage(index);
          setState(() {
            _currentPageIndex = index;
          });
        },
        items: [
          _bottomNavigatorItem('首页', Icons.home, 0),
          _bottomNavigatorItem('搜索', Icons.search, 1),
          _bottomNavigatorItem('旅拍', Icons.camera, 2),
          _bottomNavigatorItem('我的', Icons.account_balance, 3),
        ],
      ),
    );
  }

  _bottomNavigatorItem(String title, IconData icon, int index){
    return BottomNavigationBarItem(
      icon: Icon(icon,color: _defaultColor),
      activeIcon: Icon(icon, color: _activeColor),
      label: title
    );
  }
}
